﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PhpDocBlockGenerator.Model;
using PhpDocBlockGenerator.ViewModel;
using PhpDocBlockGenerator.ViewModel.Communication;
using PhpDocBlockGenerator.Views;

namespace PhpDocBlockGenerator
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// ctor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            var vm = DataContext as MainViewModel;
            if (vm != null)
            {
                vm.Notice += ShowNotice;
                vm.Statistics += ShowStatisticsWindow;
            }
        }

        /// <summary>
        /// displays a message box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ShowNotice(object sender, NotificationEventArgs e)
        {
            MessageBox.Show(e.Message);
        }

        /// <summary>
        /// displays the statistics window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ShowStatisticsWindow(object sender, NotificationEventArgs<Statistic> e)
        {
            var w = new StatisticsWindow();
            var svm = w.DataContext as StatisticsViewModel;
            if (svm != null)
            {
                svm.Statistic = e.Data;
            }
            w.Owner = this;
            w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            w.ShowDialog();
        }
    }
}
